import 'package:dirver/pages/home/information/index.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:dirver/widgets/page_content.dart';
import 'tab_index/index.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  State<HomePage> createState() => _HomePageState();
}

List<Widget> tabViewList = [
 TabIndex(),
 InformationPage(),
 PageContent(name: '消息'),
 PageContent(name: '我的'),
];

List<BottomNavigationBarItem> tabBar = [
 BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
 BottomNavigationBarItem(icon: Icon(Icons.info), label: '资讯'),
 BottomNavigationBarItem(icon: Icon(Icons.message), label: '消息'),
 BottomNavigationBarItem(icon: Icon(Icons.person), label: '我的'),
];

class _HomePageState extends State<HomePage> {
  int _currentIndex = 0;

  void _bottomNavigationBarTapped(int index) {
    setState(() {
      _currentIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion<SystemUiOverlayStyle>(
      value: SystemUiOverlayStyle(
        // 设置状态栏背景色为透明，让内容延伸到状态栏
        statusBarColor: Colors.transparent,
        // 根据当前页面内容调整状态栏图标颜色
        statusBarIconBrightness: _currentIndex == 0 ? Brightness.light : Brightness.dark,
        statusBarBrightness: _currentIndex == 0 ? Brightness.dark : Brightness.light,
      ),
      child: Scaffold(
        // 让body延伸到状态栏区域
        extendBodyBehindAppBar: true,
        body: tabViewList[_currentIndex],
        bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          items: tabBar,
          currentIndex: _currentIndex,
          onTap: _bottomNavigationBarTapped,
          selectedItemColor: Colors.green,
        ),
      ),
    );
  }

}